package com.hopes.bizz.risk.control.vo;

import com.alibaba.fastjson.JSONObject;
import com.hopes.bizz.common.core.util.StringUtils;
import com.hopes.bizz.risk.common.constant.enums.RiskSysDictEnum;
import com.hopes.bizz.risk.control.entity.RiskUnitEntity;
import com.hopes.boss.admin.api.resolver.DictResolver;
import com.hopes.boss.admin.api.resolver.enums.AdminDictEnum;
import com.hopes.boss.admin.api.resolver.enums.SysDictEnum;
import com.hopes.boss.common.entity.BaseLogicEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author daijie
 * @version 1.0
 * @date 2023/7/18 10:16
 * @Description:
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Schema(description = "风险分析对象VO")
public class RiskObjectVO extends BaseLogicEntity {

    private static final long serialVersionUID = 1L;

    @Schema(description="id")
    private Long id;

    @Schema(description="风险对象类型")
    private Integer hazardType;

    @Schema(description="风险对象名称")
    private String hazardName;

    @Schema(description="风险对象编码")
    private String hazardCode;

    @Schema(description="是否重大危险源")
    private Boolean hazardSourceFlag;

    @Schema(description="固有风险等级")
    private Integer riskLevel;

    @Schema(description="固有风险值")
    private Integer riskValue;

    @Schema(description="固有风险描述")
    private String riskDesc;

    @Schema(description="控制后风险值")
    private Integer afterRiskValue;

    @Schema(description="控制后风险等级")
    private Integer afterRiskLevel;

    @Schema(description="控制后风险描述")
    private String afterRiskDesc;

    @Schema(description="责任部门")
    private String deptId;

    @Schema(description="责任岗位")
    private String postId;

    @Schema(description="负责人")
    private String principal;

    @Schema(description="管控层级")
    private String controlLevel;

    @Schema(description="重大危险源标识")
    private Long hazardSourceId;

    @Schema(description="重大危险源等级")
    private Integer hazardSourceLevel;

    @Schema(description="主要负责人")
    private String mainUserId;

    @Schema(description="技术负责人")
    private String techUserId;

    @Schema(description="操作负责人")
    private String operateUserId;

    @Schema(description="经度")
    private String longitude;

    @Schema(description="纬度")
    private String latitude;

    @Schema(description="高度")
    private String altitude;

    @Schema(description="范围")
    private String areaScope;

    @Schema(description="位置描述")
    private String areaDesc;

    @Schema(description="二维码")
    private String qrCode;

    @Schema(description="NFC编码")
    private String nfcCode;

    @Schema(description="备注")
    private String remarks;

    @Schema(description="照片")
    private String img;

    @Schema(description="数据是否上报")
    private Boolean reportDataFlag;

    @Schema(description="机构ID")
    private Long orgId;

    // 包保责任人统计
    private JSONObject safetyStatistics;

    private Integer riskUnitNum;

    private List<RiskUnitEntity> riskUnitList;

//    public String getColor(){
//        LabelValue labelValue = DictResolver.getItemByValue(DicRiskEnum.RISK_LEVEL, this.getRiskLevel());
//        if (labelValue != null){
//            return labelValue.getExt2();
//        }
//        return null;
//    }

    public String getDeptIdStr() {
        return DictResolver.getItemLabelByValue(AdminDictEnum.sys_dept, this.getDeptId());
    }

    public String getPrincipalStr() {
        return DictResolver.getItemLabelByValue(AdminDictEnum.sys_user, this.getPrincipal());
    }

    public String getMainUserIdStr() {
        return DictResolver.getItemLabelByValue(AdminDictEnum.sys_user, this.getMainUserId());
    }

    public String getTechUserIdStr() {
        return DictResolver.getItemLabelByValue(AdminDictEnum.sys_user, this.getTechUserId());
    }

    public String getOperateUserIdStr() {
        return DictResolver.getItemLabelByValue(AdminDictEnum.sys_user, this.getOperateUserId());
    }


    public String getRiskLevelStr() {
        return DictResolver.getItemLabelByValue(RiskSysDictEnum.risk_level, this.getRiskLevel());
    }

    public String getHazardSourceLevelStr() {
        return DictResolver.getItemLabelByValue(RiskSysDictEnum.hazard_source_level, this.getHazardSourceLevel());
    }

    public String getHazardSourceFlagStr() {
        return DictResolver.getItemLabelByValue(SysDictEnum.yes_no_type, this.getHazardSourceFlag());
    }

    public String getReportDataFlagStr() {
        return DictResolver.getItemLabelByValue(SysDictEnum.yes_no_type, this.getReportDataFlag());
    }

    public String getAreaScopeStr() {
        if (StringUtils.isBlank(this.getAreaScope())) {
            return "未标定";
        } else {
            return "已标定";
        }
    }

    public String getControlLevelStr() {
        return DictResolver.getItemLabelByValue(RiskSysDictEnum.risk_control_level, this.getControlLevel());
    }

    public String getHazardTypeStr() {
        return DictResolver.getItemLabelByValue(RiskSysDictEnum.risk_object_type, this.getHazardType());
    }

    public List<Long> getDeptIdList() {
        List<Long> deptList = new ArrayList<>();
        for (String s : this.deptId.split(StringUtils.COMMA)) {
            deptList.add(Long.parseLong(s));
        }
        return deptList;
    }

    public List<Long> getPrincipalIdList() {
        List<Long> list = new ArrayList<>();
        for (String s : this.principal.split(StringUtils.COMMA)) {
            list.add(Long.parseLong(s));
        }
        return list;
    }
}
